/* *****************************************************************************************
 
Made by www.Flashphoner.com, all rights reserved.
These sources can only be used for working with Flashphoner server.
If you want use this to create your own application (separate from Flashphoner server) � 
please contact support@flashphoner.com 

******************************************************************************************/

package com.flashphoner.api.management
{
	import com.flashphoner.Logger;
	import com.flashphoner.api.data.PhoneConfig;
	
	import flash.media.Camera;
	/**
	 * Control class (singelton) for cameras
	 **/
	public class VideoControl
	{
		private static var videoControl:VideoControl;
		private var cam:Camera;
		
		public function VideoControl()
		{
			if (PhoneConfig.VIDEO_ENABLED){
				cam = Camera.getCamera();
				cam.setMode(176,144,15,false);
				cam.setKeyFrameInterval(48);
				cam.setQuality(0,95);
				cam.setMotionLevel(0,2000);
			}			
		}
		
		/**
		 * Get instance of singelton
		 **/
		public static function getInstance():VideoControl{
			if (videoControl == null){
				videoControl = new VideoControl();
			}
			return videoControl;
		}
		
		/**
		 * Get current camera to used Flashphoner
		 **/
		public function getCam():Camera{
			return cam;
		}
		
		/**
		 * Change output format CIF/QCIF
		 **/
		public function changeFormat(format:String):void{
			Logger.info("VideoControl.changeFormat format: "+format);
			if ("cif"==format){
				cam.setMode(352,288,15,false);
			} else if ("qcif"==format) {
				cam.setMode(176,144,15,false);				
			} else {
				Logger.info("Unknown video format: "+format);
			}
		}

  		/**
		 * change current camera to used Flashphoner
		 **/
		public function changeCamera(camera:Camera):void{
			if (PhoneConfig.VIDEO_ENABLED){
				camera.setMode(176,144,15,false);
				camera.setKeyFrameInterval(48);
				camera.setQuality(0,95);
				camera.setMotionLevel(0,2000);	
				this.cam = camera;			
			}
		}
	}
}